/**
 *
 * @author spider
 */
package br.unb.core;

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

import br.unb.graphics.GraphicInterface;
import br.unb.plugins.geral.view.XmlFactory;
import br.unb.core.dispatcher.Dispatcher;
import br.unb.core.manager.Manager;
import br.unb.core.status.Status;
import br.unb.utils.Console;
import br.unb.utils.Path;
import br.unb.utils.Resource;

public class Core {
    //no lazy initialization allowed! init every single class needed at the 
    //beginning of the program to avoid null references

    private static final Resource r = new Resource();
    private static final Path p = new Path();
    private static final XmlFactory x = new XmlFactory();
    //The Core of the program is done in the Dispatcher class below
    private static Manager m;//There is a thread inside this
    private static Dispatcher d;//There is a thread inside this
    private static Status s;//There is a thread inside this
    //
    private static GraphicInterface g;//A thread will be created from this
    private static boolean setupGUI = true;

    public static void main(String[] args) {
        Thread t = Thread.currentThread();
        t.setName("Main");
        m = Manager.getInstance();
        d = Dispatcher.getInstance();//inits other threads here
        s = Status.getInstance();

        if (args.length > 1 && (args[0]).equalsIgnoreCase("nogui")) {
            setupGUI = false;
        } else if (!setupGUI) {
            Object answer = JOptionPane.showConfirmDialog(null, "Load Graffic Interface ?");
            if (((Integer) answer) == JOptionPane.NO_OPTION) {
                setupGUI = false;
            }
        }
        if (setupGUI) {

            SwingUtilities.invokeLater(new Runnable() {
                //Among the threads created, there will be the "AWT-EventQueue-0", which runs the graphic interface.

                public void run() {
                    g = GraphicInterface.getInstance();
                }
            });

        } else {
            Console.println("No GUI Interface!");
        }

    }
}
